import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

import '../../../../http/bean/ywx_limit.dart';
import 'item/ui_contractroyaltyrateapplycheck.dart';
import 'item/ui_contractroyaltyrateapplycheck_update.dart';
import 'item/ui_contractroyaltyrateapplycheckchange.dart';

///提成比例审核详情
class ContractRoyaltyRateApplyCheckDetailsRoute extends StatefulWidget {
  YwxItem item;

  ContractRoyaltyRateApplyCheckDetailsRoute(this.item);

  @override
  _State createState() => _State();
}

class _State extends State<ContractRoyaltyRateApplyCheckDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    var mDatas = presenter?.mDatas?.ContractRoyaltyRateApplyCheck;
    var mOldDatas = presenter?.mOldDatas?.ContractRoyaltyRateApplyCheck;
    List<Widget> children = [];
    bool onlyBack = false;
    // print(
    //     "====================================================================更改记录${widget.item.changerecord}");
    if (widget.item.changerecord) {
      onlyBack = true;
      //更改记录里，不显示更改设置；
    } else {
      children.add(UiContractRoyaltyRateApplyCheckChange.build(context, mDatas,
          index: 0)); //更改设置
    }
    children.add(UiContractRoyaltyRateApplyCheck.build(
        context, mDatas, mOldDatas)); //基本信息
    children.add(UiContractRoyaltyRateApplyCheckUpdate.build(
        context,
        mDatas?.ModifyContractRoyaltyRate,
        mOldDatas?.ModifyContractRoyaltyRate,
        mDatas)); //修改提成比例
    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    var hasBack = true;
    if (mDatas?.isN4029() ?? false) {
      hasBack = false; //发起状态，没有退回选项
    }
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              hasBack: hasBack,
              onlyBack: onlyBack,
              callbackWithT: (subData) {
                //fixme 提交参数数据
                subData.ModifyContractRoyaltyRate =
                    mDatas?.ModifyContractRoyaltyRate; //修改提成比例
              },
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
